package com.mycompany.j2eem.controller;

import com.mycompany.j2eem.Entity.JsonResult;
import com.mycompany.j2eem.Entity.ResultCode;
import com.mycompany.j2eem.service.wucyservice.MessageService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;

@RestController
public class MessageController {

    @Autowired
    MessageService messageservice;

    private String getUsername(HttpSession session) {
        return session.getAttribute("username").toString();
    }

    //返回用户消息
    @RequestMapping("/GetUserMessage")
    public JsonResult getUserMessage(HttpSession session) {
        String username = getUsername(session);
        return messageservice.get_User_Message(username);
    }

    //消息已读
    @RequestMapping("/Read")
    public JsonResult read(@RequestParam("messageID") String messageID, HttpSession session) {
        return messageservice.read_Message(messageID);
    }

    //发送用户消息
    @RequestMapping("/Send_User_Message")
    public JsonResult sendmessage(@RequestParam("id") String id,HttpSession session,@RequestParam("operation") String operation){
        String username = getUsername(session);
        return messageservice.send_Message(username, id, operation);
    }
}
